<template>
    <div class="cart-popup" v-show="value">
        <div class="mask" @click="close" :class="{ 'mask-show': value }"></div>
        <div class="body" :class="{ 'body-show': value }">
            <div class="header row">
                <div class="text">购物车</div>
                <div class="btn-clear-cart" @click="clearCart">清空购物车</div>
            </div>
            <div class="scroll-view">
                <div class="cart-list">
                    <div
                        class="item"
                        v-for="(cartItem, index) in cartMapList"
                        :key="index"
                    >
                        <CartItem :item="cartItem" />
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import CartItem from "./cartItem";
export default {
    components: {
        CartItem
    },
    props: {
        value: Boolean
    },
    computed: {
        cartMapList() {
            return this.$store.getters.cartMapList;
        }
    },
    data() {
        return {};
    },

    methods: {
        close() {
            this.$emit("input", false);
        },
        clearCart() {
            this.$store.commit("clearCart", {});
            this.close();
        }
    }
};
</script>


<style lang="less" scoped>
.cart-popup {
    position: fixed;
    z-index: 900;
    bottom: 210px;
    width: 100%;
    font-size: 26px;

    .mask {
        position: fixed;
        z-index: 899;
        top: 0;
        left: 0;
        right: 0;
        bottom: 210px;
        background: rgba(0, 0, 0, 0.5);
    }
    .body {
        position: relative;
        z-index: 900;
        .header {
            position: relative;
            z-index: 900;
            background: #f4f4f4;
            padding: 0 30px;
            height: 60px;
            line-height: 60px;
            font-size: 24px;
            justify-content: space-between;
        }

        .scroll-view {
            position: relative;
            z-index: 900;
            background: #fff;
            width: 100%;
            max-height: 800px;
            box-sizing: border-box;
            padding: 0 0 0 0;
            overflow-y: scroll;
        }
    }

    .body-show {
        animation: showbody 0.4s;
    }
    .mask-show {
        animation: showmask 0.4s;
    }
    @keyframes showmask {
        0% {
            opacity: 0;
        }
        100% {
            opacity: 1;
        }
    }
    @keyframes showbody {
        0% {
            transform: translateY(100%);
        }
        100% {
            transform: translateY(0);
        }
    }
}
</style>